<?php


class area{

	private static $instance;

	public $len = 0;

	private $grid = array();


	public function getInstance($iLen = 0){
/*{{{*/
		if(!(self::$instance instanceof area)){

			self::$instance = new area($iLen);

		}

		return area::$instance;
/*}}}*/
	}

	private function __construct($iLen){
/*{{{*/
		$this -> len = $iLen;

		$this -> grid = array();

		for($x = 0; $x < $this -> len; $x ++){
			$this -> grid[$x] = new cell(new coord($x));
		}
/*}}}*/
	}

	public function printMap(){
/*{{{*/
		$table = new Console_Table();
		$table -> setHeaders(array('area', 'items cnt', 'items'));

		for($x = 0; $x < $this -> len; $x++){

			$table -> addRow(array(
					$x,
					$this -> grid[$x] -> getItemsCnt(),
					$this -> grid[$x] -> getItemsSymbols(),
				));
		}

		echo $table -> getTable();
/*}}}*/
	}

	public function setMyRandomLocation(item $item){
/*{{{*/
		$x = rand(0, $this -> len - 1);
		$this -> setItemLocation($item, new coord($x));
/*}}}*/
	}

	public function setItemLocation(item $item, coord $c, $removeFromPreviousLocation = false){
/*{{{*/

		if($removeFromPreviousLocation){
			$this -> removeItem($item);
		}

		$item -> setCoord($c);
		$this -> grid[$c -> x] -> addItem($item);
/*}}}*/
	}

	public function removeItem(item $it){
/*{{{*/
		// usuń z cell
		$this -> grid[$it -> getCoord() -> x] -> removeItem($it);
/*}}}*/
	}

	public function getMyNBs(item $it){


		// wszystkie itemy z tej komorki
	
	}



}



?>
